package edu.zut.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

//@Configuration
public class DateConverter implements Converter<String, LocalDate> {
    /**
     * 自定义类型转换器的转换方法
     * @param source 源数据
     * @return 目标数据
     */
    @Override
    public LocalDate convert(String source) {
        LocalDate localDate = null;
        if (null == source)
            localDate = LocalDate.now();
        else
            localDate = LocalDate.parse(source, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        return localDate;
    }
}
